﻿using SharpDX;
using SharpDX.Direct3D11;

namespace Engine.Graphics.Shaders
{
    public class SamplerStateCollection
    {
        #region Public Properties

        public static SamplerState DepthTexSampler { get; set; }

        public static SamplerState EnvMapSampler { get; set; }

        public static SamplerState Standard { get; set; }

        #endregion Public Properties

        #region Public Methods

        public static void Init(Device device)
        {
            int anisotropyLevele = 16;
            // Create samplerstate
            SamplerStateDescription samplerStateDescription = new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(0),
                ComparisonFunction = Comparison.Always,
                Filter = Filter.Anisotropic,
                MaximumAnisotropy = anisotropyLevele,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0
            };

            Standard = new SamplerState(device, samplerStateDescription);
            Standard.DebugName = "SamplerState Standard";

            // Create samplerstate
            SamplerStateDescription samplerStateDescriptionEnv = new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = new Color4(0),
                ComparisonFunction = Comparison.Always,
                Filter = Filter.Anisotropic,
                MaximumAnisotropy = anisotropyLevele,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0
            };

            EnvMapSampler = new SamplerState(device, samplerStateDescriptionEnv);
            //EnvMapSampler.DebugName = "SamplerState EnvMapSampler";

            // Create samplerstate
            SamplerStateDescription samplerStateDescriptionDepth = new SamplerStateDescription()
            {
                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                BorderColor = new Color4(0),
                ComparisonFunction = Comparison.Always,
                Filter = Filter.MinMagMipPoint,
                MaximumAnisotropy = anisotropyLevele,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0
            };

            DepthTexSampler = new SamplerState(device, samplerStateDescriptionDepth);
            //DepthTexSampler.DebugName = "SamplerState DepthTexSampler";
        }

        #endregion Public Methods
    }
}